package com.djstl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.djstl.Graph.Cell;

public class Djstl {
	
	private Map<Integer,Integer> map=new HashMap<Integer,Integer>();
	private int start=0;
	public void showMiniPath(List<Cell>[] list){	
	while(true){		
	   
		int min_cell_num=-1;
	    int min_cell_path=Integer.MAX_VALUE;
	   
	   //straight linked cell
	   for(int i=0;i<list[start].size();i++){		   
		   Cell cell=list[start].get(i);
		   int cell_num   =cell.getCellNum();
		   int cell_weight=cell.getWeight();
		   if(cell_weight<min_cell_path && map.get(cell_num)==null){
			   min_cell_num   =cell_num;
			   min_cell_path=cell_weight;
		   }
	   }
	   // map straight linked cell
	   Iterator<Integer> iter=map.keySet().iterator(); 
	   while(iter.hasNext()){
		  int map_cell_num=iter.next();
		  int map_cell_path=map.get(map_cell_num);
		  for(int i=0;i<list[map_cell_num].size();i++){
			Cell cell=list[map_cell_num].get(i);
			if( map.get(cell.getCellNum())==null 
			    && cell.getWeight()+map_cell_path<min_cell_path){
				min_cell_num=cell.getCellNum();
				min_cell_path=cell.getWeight()+map_cell_path;
			}  
		  } 
	   }
	   if(min_cell_path<Integer.MAX_VALUE){
		   map.put(min_cell_num,min_cell_path);
	   }else{
		   break;
	   }
	 }	
	 System.out.println(map);
   }
}
